'''
Created on Sep 4, 2012

@author: peng
'''

import pycurl
import StringIO
import json

post_dict_1 = {"body":[{"val":1, "ctg":"c", "t":1346675012727, "act":"a", "lab":"l"}],
            "header":
            {"res": "480*800",
             "os":"Android",
             "nt":"1",
             "model":"Nexus S",
             "lon":"0.0",
             "appvn":"1.0",
             "osv":"4.1.1",
             "no":"46000",
             "cpu":"ARMv7 Processor rev 2 (v7l)",
             "did":"167a24d0-17a5-4565-a8ed-d923192f2b6e",
             "isu":"152c54af2878cfdf04b809913160a59a",
             "lang":"zh",
             "appvc":"1",
             "sdkv":"1.1",
             "pn":"com.example.sdktest",
             "app_id":"",
             "chn":"ANDROID_MARKET",
             "lat":"0.0",
             "cc":"CN"}}

post_dict_2 = {"body":[{"val":1, "ctg":"c", "t":1346677428628, "act":"a", "lab":"l"}, {"val":1, "ctg":"c", "t":1346677428635, "act":"a", "lab":"l"}, {"val":1, "ctg":"c", "t":1346677428637, "act":"a", "lab":"l"}, {"val":1, "ctg":"c", "t":1346677428648, "act":"a", "lab":"l"}, {"val":1, "ctg":"c", "t":1346677428653, "act":"a", "lab":"l"}, {"val":1, "ctg":"c", "t":1346677428662, "act":"a", "lab":"l"}], "header":{"res":"480*800", "os":"Android", "nt":"1", "model":"Nexus S", "lon":"0.0", "appvn":"1.0", "osv":"4.1.1", "no":"46000", "cpu":"ARMv7 Processor rev 2 (v7l)", "did":"167a24d0-17a5-4565-a8ed-d923192f2b6e", "isu":"152c54af2878cfdf04b809913160a59a", "lang":"zh", "appvc":"1", "sdkv":"1.1", "pn":"com.example.sdktest", "app_id":"", "chn":"ANDROID_MARKET", "lat":"0.0", "cc":"CN"}}

post_dict_3 = {"body":[{"val":1, "ctg":"__##BELUGA##__", "t":1346762645008, "act":"__##ACTIVATE##__", "lab":"ACTIVATE"}, {"val":1, "ctg":"__##BELUGA##__", "t":1346762645066, "act":"__##LAUNCH##__", "lab":"LAUNCH"}, {"val":1, "ctg":"__##BELUGA##__", "t":1346762645068, "act":"__##ACTIVE##__", "lab":"ACTIVE"}], "header":{"res":"480*800", "os":"Android", "nt":"1", "model":"Nexus S", "lon":"114.4123277", "appvn":"8.8.0 beta3", "osv":"4.0.3", "no":"46000", "cpu":"ARMv7 Processor rev 2 (v7l)", "did":"ddd4f73b-7421-46fb-9f12-36d51ee316e3", "isu":"6e8ffe7b3fb6b5e11da0af5555a6c877", "lang":"en", "appvc":"167", "sdkv":"1.1", "pn":"mobi.mgeek.TunnyBrowser", "app_id":"6e1cd3bc2cda139a29b552ae5d742b80", "chn":"ofw", "lat":"30.5029667", "cc":"US"}}

post_dict_4 = {"body":[{"val":1, "ctg":"addon bar", "t":1346762673031, "act":"install", "lab":"811711abd41cd659c819d87108f22bce"}, {"val":1, "ctg":"theme", "t":1346762682948, "act":"install", "lab":"811711abd41cd659c819d87108f22bce"}, {"val":1, "ctg":"bookmark bar", "t":1346762700180, "act":"clickurl", "lab":"8fb2db9e912af0898ce9142cf8cf0b22"}, {"val":4, "ctg":"speed dial", "t":1346762706192, "act":"count", "lab":"4-4"}, {"val":1, "ctg":"dolphin account", "t":1346762707685, "act":"launch", "lab":"dolphinconnect"}, {"val":1, "ctg":"bookmark bar", "t":1346762710043, "act":"clickurl", "lab":"957a6cbd59335594a5f87237e18cb0fb"}, {"val":1, "ctg":"addon bar", "t":1346762712890, "act":"active", "lab":"811711abd41cd659c819d87108f22bce"}, {"val":1, "ctg":"bookmark bar", "t":1346762716774, "act":"clickurl", "lab":"fd097ec2a41f6539015bda21725b30b2"}, {"val":1, "ctg":"dolphin account", "t":1346762821192, "act":"launch", "lab":"dolphinconnect"}], "header":{"res":"480*800", "os":"Android", "nt":"1", "model":"Nexus S", "lon":"114.4123277", "appvn":"8.8.0 beta3", "osv":"4.0.3", "no":"46000", "cpu":"ARMv7 Processor rev 2 (v7l)", "did":"ddd4f73b-7421-46fb-9f12-36d51ee316e3", "isu":"6e8ffe7b3fb6b5e11da0af5555a6c877", "lang":"en", "appvc":"167", "sdkv":"1.1", "pn":"mobi.mgeek.TunnyBrowser", "app_id":"6e1cd3bc2cda139a29b552ae5d742b80", "chn":"ofw", "lat":"30.5029667", "cc":"US"}}

post_dict_5 = {"body":[{"val":1, "ctg":"home", "t":1346763188080, "act":"hardkey", "lab":"menu"},
                       {"val":1, "ctg":"home", "t":1346763190212, "act":"hardkey", "lab":"menu"},
                       {"val":1, "ctg":"menu bar", "t":1346763192524, "act":"clickbtn", "lab":"download"},
                       {"val":1, "ctg":"home", "t":1346763201847, "act":"hardkey", "lab":"menu"},
                       {"val":1, "ctg":"menu bar", "t":1346763203698, "act":"clickbtn", "lab":"settings"},
                       {"val":1, "ctg":"settings", "t":1346763208044, "act":"user_agent", "lab":"0"},
                       {"val":1, "ctg":"settings", "t":1346763208695, "act":"pref_search_engine", "lab":"-"},
                       {"val":1, "ctg":"settings", "t":1346763210526, "act":"search_engine", "lab":"2"},
                       {"val":1, "ctg":"settings", "t":1346763212088, "act":"enable_search_suggestion", "lab":"disable"},
                       {"val":1, "ctg":"settings", "t":1346763212707, "act":"enable_search_suggestion", "lab":"enable"},
                       {"val":1, "ctg":"settings", "t":1346763214439, "act":"pref_search_engine", "lab":"-"},
                       {"val":1, "ctg":"settings", "t":1346763216738, "act":"search_engine", "lab":"1"},
                       {"val":1, "ctg":"settings", "t":1346763217643, "act":"search_engine", "lab":"0"},
                       {"val":1, "ctg":"settings", "t":1346763218400, "act":"search_engine", "lab":"2"},
                       {"val":1, "ctg":"settings", "t":1346763220819, "act":"is_default_browser", "lab":"enable"},
                       {"val":1, "ctg":"settings", "t":1346763222839, "act":"is_default_browser", "lab":"disable"},
                       {"val":1, "ctg":"settings", "t":1346763223487, "act":"pref_vg_settings", "lab":"-"},
                       {"val":5, "ctg":"gesture", "t":1346763223796, "act":"count", "lab":"1-5"},
                       {"val":1, "ctg":"gesture", "t":1346763224712, "act":"edit", "lab":"load url:http:\/\/blog.dolphin-browser.com\/"},
                       {"val":5, "ctg":"gesture", "t":1346763234556, "act":"count", "lab":"1-5"},
                       {"val":1, "ctg":"dolphin voice", "t":1346763240384, "act":"clickbtn", "lab":"shortcut"},
                       {"val":1, "ctg":"dolphin voice", "t":1346763241414, "act":"createsonarshortcut", "lab":"ok"},
                       {"val":1, "ctg":"dolphin voice", "t":1346763242140, "act":"voicelanguage", "lab":"zh"},
                       {"val":1, "ctg":"settings", "t":1346763244690, "act":"pref_dolphin_service_settings", "lab":"-"},
                       {"val":1, "ctg":"dolphin account", "t":1346763244962, "act":"launch", "lab":"dolphinconnect"},
                       {"val":1, "ctg":"dolphin account", "t":1346763246237, "act":"signin", "lab":"nonfacebook"},
                       {"val":1, "ctg":"dolphin account", "t":1346763247227, "act":"signin", "lab":"dolphinaccount"},
                       {"val":1, "ctg":"dolphin account", "t":1346763248962, "act":"back", "lab":"dolphinconnect"},
                       {"val":1, "ctg":"settings", "t":1346763251196, "act":"pref_dolphin_service_settings", "lab":"-"},
                       {"val":1, "ctg":"dolphin account", "t":1346763251368, "act":"launch", "lab":"dolphinconnect"},
                       {"val":1, "ctg":"settings", "t":1346763254125, "act":"pref_web_content", "lab":"-"},
                       {"val":1, "ctg":"settings", "t":1346763257126, "act":"text_size", "lab":"0"},
                       {"val":1, "ctg":"settings", "t":1346763258878, "act":"plugin_state", "lab":"0"},
                       {"val":1, "ctg":"settings", "t":1346763259788, "act":"load_page", "lab":"disable"},
                       {"val":1, "ctg":"settings", "t":1346763260897, "act":"load_page", "lab":"enable"},
                       {"val":1, "ctg":"settings", "t":1346763262671, "act":"load_images_state", "lab":"1"},
                       {"val":1, "ctg":"settings", "t":1346763264780, "act":"load_images_state", "lab":"0"},
                       {"val":1, "ctg":"settings", "t":1346763265679, "act":"enable_javascript", "lab":"disable"},
                       {"val":1, "ctg":"settings", "t":1346763266539, "act":"enable_javascript", "lab":"enable"},
                       {"val":1, "ctg":"settings", "t":1346763267949, "act":"block_popup_windows", "lab":"disable"},
                       {"val":1, "ctg":"settings", "t":1346763268673, "act":"block_popup_windows", "lab":"enable"},
                       {"val":1, "ctg":"settings", "t":1346763269233, "act":"show_security_warnings", "lab":"disable"},
                       {"val":1, "ctg":"settings", "t":1346763269916, "act":"show_security_warnings", "lab":"enable"},
                       {"val":1, "ctg":"settings", "t":1346763272097, "act":"pref_vg_settings", "lab":"-"},
                       {"val":5, "ctg":"gesture", "t":1346763272901, "act":"count", "lab":"1-5"},
                       {"val":1, "ctg":"settings", "t":1346763275120, "act":"pref_help", "lab":"-"},
                       {"val":1, "ctg":"settings", "t":1346763277262, "act":"about", "lab":"-"},
                       {"val":1, "ctg":"settings", "t":1346763280608, "act":"pref_privacy_data", "lab":"-"},
                       {"val":1, "ctg":"settings", "t":1346763282500, "act":"accept_cookies", "lab":"enable"},
                       {"val":1, "ctg":"settings", "t":1346763283449, "act":"accept_cookies", "lab":"disable"},
                       {"val":1, "ctg":"settings", "t":1346763284846, "act":"enable_geolocation", "lab":"enable"},
                       {"val":1, "ctg":"settings", "t":1346763285687, "act":"enable_geolocation", "lab":"disable"}, {"val":1, "ctg":"settings", "t":1346763286180, "act":"save_formdata", "lab":"enable"}, {"val":1, "ctg":"settings", "t":1346763287520, "act":"save_formdata", "lab":"disable"}, {"val":1, "ctg":"settings", "t":1346763287980, "act":"remember_passwords", "lab":"enable"}, {"val":1, "ctg":"settings", "t":1346763288487, "act":"accept_cookies", "lab":"enable"}, {"val":1, "ctg":"settings", "t":1346763289069, "act":"accept_cookies", "lab":"disable"}, {"val":1, "ctg":"settings", "t":1346763289727, "act":"remember_passwords", "lab":"disable"}, {"val":1, "ctg":"home", "t":1346763293568, "act":"hardkey", "lab":"menu"}, {"val":1, "ctg":"tab bar", "t":1346763294709, "act":"click", "lab":"closetab2"}, {"val":1, "ctg":"tab bar", "t":1346763295467, "act":"click", "lab":"newtab"}, {"val":1, "ctg":"home", "t":1346763298848, "act":"hardkey", "lab":"menu"}, {"val":1, "ctg":"tab bar", "t":1346763299621, "act":"click", "lab":"closetab1"}, {"val":1, "ctg":"tab bar", "t":1346763300279, "act":"click", "lab":"closetab1"}, {"val":1, "ctg":"home", "t":1346763301685, "act":"swipe", "lab":"bookmarkbar"}, {"val":1, "ctg":"bookmark bar", "t":1346763303437, "act":"clickurl", "lab":"d339dad3c77ff9f352aa795d6dce9a5b"}, {"val":1, "ctg":"bookmark bar", "t":1346763303442, "act":"clickpos", "lab":"3"}, {"val":1, "ctg":"home", "t":1346763306153, "act":"swipe", "lab":"bookmarkbar"}, {"val":1, "ctg":"bookmark bar", "t":1346763308769, "act":"bookmarklongpress", "lab":"delete"}, {"val":1, "ctg":"bookmark bar", "t":1346763311597, "act":"bookmarklongpress", "lab":"addshortcuthome"}, {"val":1, "ctg":"home", "t":1346763314047, "act":"hardkey", "lab":"menu"}, {"val":1, "ctg":"tab bar", "t":1346763315492, "act":"click", "lab":"newtab"}, {"val":1, "ctg":"tab bar", "t":1346763315926, "act":"click", "lab":"newtab"}, {"val":1, "ctg":"tab bar", "t":1346763316667, "act":"num", "lab":"4"}, {"val":1, "ctg":"tab bar", "t":1346763316697, "act":"click", "lab":"newtab"}, {"val":1, "ctg":"tab bar", "t":1346763317214, "act":"click", "lab":"newtab"}, {"val":1, "ctg":"tab bar", "t":1346763317815, "act":"click", "lab":"newtab"}, {"val":1, "ctg":"tab bar", "t":1346763318660, "act":"click", "lab":"closetab1"}, {"val":1, "ctg":"tab bar", "t":1346763319346, "act":"click", "lab":"closetab1"}, {"val":1, "ctg":"tab bar", "t":1346763319903, "act":"click", "lab":"closetab1"}, {"val":1, "ctg":"tab bar", "t":1346763320816, "act":"click", "lab":"closetab1"}, {"val":1, "ctg":"tab bar", "t":1346763321747, "act":"click", "lab":"closetab1"}, {"val":1, "ctg":"tab bar", "t":1346763322701, "act":"click", "lab":"closetab2"}, {"val":1, "ctg":"tab bar", "t":1346763323448, "act":"click", "lab":"newtab"}, {"val":1, "ctg":"tab bar", "t":1346763324230, "act":"click", "lab":"newtab"}, {"val":1, "ctg":"tab bar", "t":1346763324722, "act":"num", "lab":"4"}, {"val":1, "ctg":"tab bar", "t":1346763324740, "act":"click", "lab":"newtab"}, {"val":1, "ctg":"tab bar", "t":1346763325490, "act":"click", "lab":"closetab1"}, {"val":1, "ctg":"tab bar", "t":1346763326170, "act":"click", "lab":"closetab1"}, {"val":1, "ctg":"tab bar", "t":1346763327369, "act":"click", "lab":"newtab"}, {"val":1, "ctg":"tab bar", "t":1346763327745, "act":"num", "lab":"4"}, {"val":1, "ctg":"tab bar", "t":1346763327770, "act":"click", "lab":"newtab"}, {"val":1, "ctg":"tab bar", "t":1346763328297, "act":"click", "lab":"newtab"}, {"val":1, "ctg":"tab bar", "t":1346763328873, "act":"click", "lab":"newtab"}, {"val":1, "ctg":"tab bar", "t":1346763329989, "act":"click", "lab":"newtab"}, {"val":1, "ctg":"tab bar", "t":1346763330431, "act":"num", "lab":"8"}, {"val":1, "ctg":"tab bar", "t":1346763330460, "act":"click", "lab":"newtab"}, {"val":1, "ctg":"tab bar", "t":1346763331144, "act":"click", "lab":"newtab"}, {"val":1, "ctg":"tab bar", "t":1346763331858, "act":"click", "lab":"closetab1"}, {"val":1, "ctg":"tab bar", "t":1346763332465, "act":"click", "lab":"closetab1"}], "header":{"res":"480*800", "os":"Android", "nt":"1", "model":"Nexus S", "lon":"114.4123277", "appvn":"8.8.0 beta3", "osv":"4.0.3", "no":"46000", "cpu":"ARMv7 Processor rev 2 (v7l)", "did":"ddd4f73b-7421-46fb-9f12-36d51ee316e3", "isu":"6e8ffe7b3fb6b5e11da0af5555a6c877", "lang":"en", "appvc":"167", "sdkv":"1.1", "pn":"mobi.mgeek.TunnyBrowser", "app_id":"6e1cd3bc2cda139a29b552ae5d742b80", "chn":"ofw", "lat":"30.5029667", "cc":"US"}}

html = StringIO.StringIO()
url = r'https://aens.belugaboost.com/track/1/logs'

size = StringIO.StringIO()

c = pycurl.Curl()
c.setopt(pycurl.URL, url)
c.setopt(pycurl.POSTFIELDS, json.dumps(post_dict_1))
c.setopt(pycurl.SSL_VERIFYHOST, False)
c.setopt(pycurl.SSL_VERIFYPEER, False)
c.setopt(pycurl.WRITEFUNCTION, html.write)
c.setopt(pycurl.FOLLOWLOCATION, 1)
c.perform()
print c.getinfo(pycurl.HTTP_CODE), c.getinfo(pycurl.EFFECTIVE_URL)
print html.getvalue()
print 'response size [%s]' % html.len
print 'request size [%s]' % c.getinfo(pycurl.CONTENT_LENGTH_UPLOAD)
